package com.caigou.modules.center.ui.detail.dynamic

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseFragment
import com.caigou.comm.base.widget.SpaceItemDecoration
import com.caigou.modules.center.R
import com.caigou.modules.center.adapter.MyDynamicAdapter
import com.caigou.modules.center.bean.MyDynamicItem
import com.caigou.modules.center.databinding.FragmentMyDynamicBinding
import com.caigou.modules.center.ui.detail.DetailActivity
import dagger.hilt.android.AndroidEntryPoint

/**
 * @author #Suyghur.
 * Created on 2021/11/03
 */
@AndroidEntryPoint
class MyDynamicFragment : BaseFragment() {

    private var _binding: FragmentMyDynamicBinding? = null
    private val binding get() = _binding!!
    private val items = mutableListOf(
        MyDynamicItem(R.drawable.img_comm_hk, "港彩"),
        MyDynamicItem(R.drawable.img_comm_singapore, "新彩"),
        MyDynamicItem(R.drawable.img_comm_macao, "澳彩"),
        MyDynamicItem(R.drawable.img_comm_tw, "台彩"),
        MyDynamicItem(R.drawable.img_comm_football, "足球论坛"),
        MyDynamicItem(R.drawable.img_comm_info, "民间资料"),
        MyDynamicItem(R.drawable.img_comm_market, "猛料市场"),
        MyDynamicItem(R.drawable.img_comm_gallery, "港彩六合图库"),
        MyDynamicItem(R.drawable.img_comm_gallery2, "澳彩六合图库"),
        MyDynamicItem(R.drawable.img_comm_data, "每期资料"),
        MyDynamicItem(R.drawable.img_comm_formula, "公式规律"),
        MyDynamicItem(R.drawable.img_comm_guess, "幽默猜测"),
        MyDynamicItem(R.drawable.img_comm_run_dog, "跑狗玄机"),
        MyDynamicItem(R.drawable.img_comm_unlike, "四不像"),
        MyDynamicItem(R.drawable.img_comm_message_board, "留言板")
    )

    private val mAdapter: MyDynamicAdapter by lazy {
        MyDynamicAdapter(mutableListOf())
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _binding = FragmentMyDynamicBinding.inflate(inflater, container, false)
        return _binding?.root
    }


    override fun initView() {
        binding.myDynamicRecyclerViewList.run {
            layoutManager = GridLayoutManager(requireActivity(), 2)
            adapter = mAdapter
            itemAnimator = DefaultItemAnimator()
            addItemDecoration(SpaceItemDecoration(requireActivity()))
        }

        mAdapter.setOnItemClickListener { adapter, view, position ->
            when (position) {
                0 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_HK_TICKET_DYNAMIC)
                1 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_SINGAPORE_TICKET_DYNAMIC)
                2 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_MACAO_TICKET_DYNAMIC)
                3 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_TW_TICKET_DYNAMIC)
                4 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_SOCCER_TICKET_DYNAMIC)
                5 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_INFO_DYNAMIC)
                6 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_MARKET_DYNAMIC)
                7 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_HK_GALLERY_DYNAMIC)
                8 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_MACAO_GALLERY_DYNAMIC)
                9 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_DATA_DYNAMIC)
                10 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_LAW_DYNAMIC)
                11 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_GUESS_DYNAMIC)
                12 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_RUN_DOG_DYNAMIC)
                13 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_UNLIKE_DYNAMIC)
                14 -> (requireActivity() as DetailActivity).switchFragment(RouterPath.Center.TAG_BOARD_DYNAMIC)
            }
        }
        mAdapter.setList(items)
    }

    override fun lazyLoad() {
    }

    override fun onBack() {
    }

    override fun observeViewModel() {
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}